<?php
namespace app\common\model;

class OrderLogistics extends Base
{
    static $status = [
                1 => '待发货',
                2 => '待签收',
                3 => '订单完成',
                0 => '订单取消',
            ];

    public static function status($key=null){
        if(!is_null($key)){
            return self::$status[$key];
        }else{
            return self::$status;
        }
    }

    /**
     * [getPageDatas 查询物流货单]
     * @param  array  $where [description]
     * @param  string $field [description]
     * @return [type]        [description]
     */
    public function getPageDatas($where=[],$page,$perpagenum,$field=''){
        $start = ($page-1)*$perpagenum;
        $whereData=[];
        if(!empty($where)){
            foreach($where as $k => $wh):
                $whereData['a.'.$k] = $wh;
            endforeach;
        }
        $data = $this
              ->alias('a')
              ->join('Logistics l','a.logis_id = l.id')
              ->where($whereData)
              ->limit($start,$perpagenum)
              ->order('a.id','DESC')
              ->field('a.*,l.title as logisname')
              ->select();
        $count = $this->alias('a')->where($whereData)->count();
        $total_page = ceil($count/$perpagenum);
        return [
            'total_page' => $total_page,
            'curent_page' => $page,
            'count' => $count,
            'data' => $data
        ];
    }

    /**
     * 查询一条物流货单
     */
    public function getOneDatas($where=[],$field=''){
        return $this
              ->alias('a')
              ->join('Logistics l','a.logis_id = l.id')
              ->where($where)
              ->field('a.*,l.title as logisname')
              ->find();
    }

    public static function del($data=[]){
        return $this->delete($data);
    }

}
